<?php declare(strict_types=1);

use Hyperf\Server\Event;
use Hyperf\Server\Server;
use Swoole\Constant;

$dependFolder = env('DEPENDS_FOLDER', '/depends');

!defined('DEPENDS_FOLDER') && define('DEPENDS_FOLDER', BASE_PATH . $dependFolder);

return [
    'mode' => SWOOLE_PROCESS,
    'servers' => [
        [
            'name' => 'http',
            'type' => Server::SERVER_HTTP,
            'host' => '0.0.0.0',
            'port' => (int)env('SERVER_PORT') ?: 9501,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ],
        ],

//        [
//            'name' => 'tcp',
//            'type' => Server::SERVER_BASE,
//            'host' => '0.0.0.0',
//            'port' => (int)env('SOCKET_PORT') ?: 9561,
//            'sock_type' => SWOOLE_SOCK_TCP,
//            'callbacks' => [
//                Event::ON_CONNECT => [App\TcpService\LinkService::class, 'onConnect'],
//                Event::ON_CLOSE => [App\TcpService\LinkService::class, 'onClose'],
//                Event::ON_RECEIVE => [App\TcpService\inkService::class, 'onReceive'],
//            ],
//            "settings" => [
//                Constant::OPTION_OPEN_LENGTH_CHECK => true,
//                Constant::OPTION_PACKAGE_MAX_LENGTH => 81920,
//                Constant::OPTION_PACKAGE_LENGTH_TYPE => 'V',
//                Constant::OPTION_PACKAGE_LENGTH_OFFSET => 0,
//                Constant::OPTION_PACKAGE_BODY_OFFSET => 12,
//            ]
//        ],
    ],
    'settings' => [
        Constant::OPTION_ENABLE_COROUTINE => true,
        Constant::OPTION_WORKER_NUM => (int)env('SERVER_WORKER') ?: swoole_cpu_num(),
        Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/service.pid',
        Constant::OPTION_OPEN_TCP_NODELAY => true,
        Constant::OPTION_MAX_COROUTINE => 100000,
        Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
        Constant::OPTION_MAX_REQUEST => 100000,
        Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
        Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
        Constant::OPTION_PACKAGE_MAX_LENGTH => 3 * 1024 * 1024
    ],
    'callbacks' => [
        Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
        Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
        Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
    ],
];
